package Java7_Concurrency_Cookbook.thread_executor_framework.rejected_execution_handler;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author lixiangke
 * @date 2017/11/21
 */
public class Task implements Runnable {
    private String name;

    public Task(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.printf("Zoom: %s Starting\n", name);
        long duration = (long) new Random().nextInt(10);
        System.out.printf("Zoom: sleep %s seconds\n", duration);
        try {
            TimeUnit.SECONDS.sleep(duration);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.printf("Zoom %s: Ending\n", name);
    }

    @Override
    public String toString() {
        return name;
    }
}
